package com.leo.m1803.d06;

/**
 * Created by LEO on 2018/3/6.
 */
public class Offer03 {
    public static boolean find(int[][] s, int target){
        int row = s.length-1;
        int col = s[0].length-1;
        int i = 0, j = col;
        while ( i<=row && j>=0){
            if (s[i][j] == target){
                return true;
            }else if (s[i][j] > target){
                j--;
            }else if (s[i][j] < target){
                i++;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        int[][] a= {{1,2,8,9},
                {2,4,9,12},
                {4,7,10,13},
                {6,8,11,15}};
        System.out.println(find(a, 9));
        System.out.println(find(a, 10));
        System.out.println(find(a, 11));
        System.out.println(find(a, 5));
        System.out.println(find(a, 6));

    }
}
